<?php

namespace app\common\model\Subject\Teacher;

use app\common\model\Business\Business;
use think\Model;

class Follow extends Model
{
    // 表名
    protected $name = 'subject_teacher_follow';
    // 忽略数据表不存在的字段
    protected $field = true;
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    //禁止写入时间字段
    protected $updateTime = false;
    // 软删除的字段
    protected $deleteTime = false;
    // 设置返回的结果类型
    protected $resultSetType = 'collection';
    // 追加属性
    protected $append = [
        // 'teacher',
        'business',
        'createDate',
    ];
    // public function getTeacherAttr($value,$data){
    //     if(!isset($data['teacherid']))return;
    //     // $teacher = Teacher::field('name,avatar,content,job,createtime')->where($data['teacherid'])->select();
    //     $teacher = $this->hasOne('teacher','id','teacherid')->field('name,avatar,content,job,createtime')->select();
    //     return $teacher?$teacher->toArray()[0]:null;
    // }
    public function business()
    {
        return $this->belongsTo(Business::class,'busid','id',[],'left')->setEagerlyType(0);
    }
    public function getCreateDateAttr($value,$data)
    {
        return date('Y-m-d',$data['createtime']);
    }
    public function teacher()
    {
        return $this->belongsTo(Teacher::class,'teacherid','id',[],'left')->setEagerlyType(0);
    }
}
